/*
 * =====================================================================================
 *
 *       Filename:  Dealer.cpp
 *
 *    Description:  Dealer program, who can hold the deck.
 *
 *        Version:  1.0
 *        Created:  10/25/11 11:39:12
 *       Revision:  none
 *       Compiler:  g++
 *
 *         Author:  LittleQ Su (), 98703060@nccu.edu.tw
 *        Company:  National Chengchi University, The Department of Computer Science
 *
 * =====================================================================================
 */
#include "headers.h"

// Constructor
Dealer::Dealer () {
    Card::Suit suit;
    this -> index = 0;
    for (int s = 1; s <= SUIT_MAX ; s++ ){
        suit = this -> _getSuit(s);
        for (int r = 1; r <= RANK_MAX ; r++) {
            this -> cards[this->index] = *(new Card(suit, r));
            this -> index ++ ;
        }
    }
    this -> index = 0;

}

// Implementation of Dealer
void Dealer::Shuffle() {
    int draw_pos;
    srand((unsigned) time(0));

    for (int rt = 0 ; rt < RAND_TIME ; ++rt) {
        draw_pos = (rand() % (DECK_MAX-1)) + 1;
        this -> _swapCard(0, draw_pos);
    }
    
}

Card Dealer::dealCard() {
    int index = this -> index;
    this -> index ++ ;
    return this -> cards[index];
}

void Dealer::_swapCard(int idx1, int idx2) {
    Card temp_card;

    temp_card = this -> cards[idx2];
    this -> cards[idx2] = this -> cards[idx1];
    this -> cards[idx1] = temp_card;
}

Card::Suit Dealer::_getSuit(int num) {
    switch (num) {
        case 1:
            return Card::CLUBS;
        case 2:
            return Card::DIAMONDS;
        case 3:
            return Card::HEARTS;
        case 4:
            return Card::SPADES;
        default:
            return Card::CLUBS;
    }
}
